package com.javakc.pms.instruction.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javakc.pms.instruction.entity.Instruction;
import com.javakc.pms.instruction.mapper.InstructionMapper;
import com.javakc.pms.instruction.service.InstructionService;
import com.javakc.servicebase.config.InstructionQuery;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class Instrucationlmpl extends ServiceImpl<InstructionMapper,Instruction> implements InstructionService  {

    @Override
    public void findPageInstruction(Page<Instruction> instructionPage, InstructionQuery instructionQuery) {
        QueryWrapper<Instruction> queryWrapper = new QueryWrapper<>();
        if(!ObjectUtils.isEmpty(instructionQuery)){
            if(!ObjectUtils.isEmpty(instructionQuery.getName())){
                queryWrapper.like("name",instructionQuery.getName());
            }
          if (!ObjectUtils.isEmpty(instructionQuery.getBeginDate())) {
            queryWrapper.ge("gmt_create", instructionQuery.getBeginDate());
          }
          if (!ObjectUtils.isEmpty(instructionQuery.getEndDate())) {
            queryWrapper.lt("gmt_create", instructionQuery.getEndDate());
          }
        }
        queryWrapper.orderByDesc("gmt_create");
        baseMapper.selectPage(instructionPage,queryWrapper);
    }
}
